package info.hexin.json.serialize.render;

import info.hexin.json.serialize.JsonRender;
import info.hexin.json.serialize.JsonSerializeConfig;
import info.hexin.json.serialize.StringWrite;

import java.util.Set;

public class SetRender implements JsonRender {
    public static SetRender instance = new SetRender();

    @Override
    public void render(Object object, StringWrite write) {
        write.append('[');
        Set<?> set = (Set<?>) object;
        int i = 0;
        int sum = set.size();
        for (Object value : set) {
            JsonRender jsonRender = JsonSerializeConfig.getRender(value.getClass());
            jsonRender.render(value, write);
            if (++i < sum) {
                write.append(',');
            }
        }
        write.append(']');
    }
}
